import {onMounted, onUnmounted, ref} from "vue";
import echarts from "@/utils/echarts";


export default function (chartRefDom: any, optionObj: any) {
    const chartRef = chartRefDom;
    let myChart: echarts.ECharts | null = null;
    onMounted(() => {
        // 初始化 ECharts 实例
        myChart = echarts.init(chartRef.value);
        // 设置图表的配置项和数据
        const option = optionObj
        // 使用配置项和数据显示图表
        myChart.setOption(option);
    });

    onUnmounted(() => {
        if (myChart) {
            myChart.dispose();
            myChart = null; // 清理引用
        }
    })
}